package com.minimalist.common.feign.client.basic;

import com.minimalist.common.entity.basic.vo.file.FileUpdateStatusVO;
import com.minimalist.common.entity.basic.vo.file.FileUploadRespVO;
import com.minimalist.common.entity.basic.vo.file.FileVO;
import com.minimalist.common.feign.config.FeignConfig;
import com.minimalist.common.feign.fallback.basic.FileFeignClientFallbackFactory;
import com.minimalist.common.response.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import jakarta.validation.constraints.NotNull;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 文件管理 Feign 客户端
 *
 * @author minimalist
 */
@FeignClient(name = "minimalist-basic"
        , contextId = "fileFeignClient"
        , path = "/minimalist/basic/api"
        , configuration = FeignConfig.class
        , fallbackFactory = FileFeignClientFallbackFactory.class)
public interface FileFeignClient{

    /**
     * 根据文件ID查询文件信息
     *
     * @param fileId 文件ID
     * @return 文件信息
     */
    @GetMapping("/getFileByFileId/{fileId}")
    R<FileVO> getFileByFileId(@PathVariable("fileId") Long fileId);

    /**
     * 根据文件ID列表查询文件信息
     *
     * @param fileIds 文件ID列表
     * @return 文件信息列表
     */
    @GetMapping("getFileListByFileIds")
    @Operation(summary = "根据文件ID列表查询文件信息")
    R<List<FileVO>> getFileListByFileIds(
            @RequestParam("fileIds") @NotNull(message = "文件ID列表不能为空")
            @Parameter(name = "fileIds", required = true, description = "文件ID列表")
            List<Long> fileIds);

    /**
     * 根据文件URL更新文件状态
     *
     * @param fileUpdateStatusVO 文件URL更新
     * @return 更新结果
     */
    @PostMapping("/updateStatusByFileUrl")
    @Operation(summary = "根据文件URL更新文件状态")
    R<Void> updateStatusByFileUrl(
            @Validated FileUpdateStatusVO fileUpdateStatusVO);

    /**
     * 单文件上传
     *
     * @param file       文件
     * @param fileSource 文件来源
     * @param createId   创建人ID
     * @param updateId   更新人ID
     * @param tanantId   租户ID
     * @return 文件信息
     */
    @PostMapping(value = "/uploadFile", consumes = "multipart/form-data")
    @Operation(summary = "单文件上传")
    R<FileUploadRespVO> uploadFile(
            @RequestPart("file") MultipartFile file,
            @RequestParam(value = "fileSource") Integer fileSource,
            @RequestParam(value = "createId") @Validated Long createId,
            @RequestParam(value = "updateId") @Validated Long updateId,
            @RequestParam(value = "tanantId") @Validated Long tanantId);

    /**
     * 单文件删除
     *
     * @param fileId 文件ID
     * @return 删除结果
     */
    @DeleteMapping("/deleteFile")
    @Operation(summary = "单文件删除")
    R<Void> deleteFile(
            @RequestParam("fileId") @NotNull(message = "文件ID不能为空")
            @Parameter(name = "fileId", required = true, description = "fileId")
            Long fileId);

    /**
     * 多文件删除
     *
     * @param fileIds 文件ID列表
     * @return 删除结果
     */
    @DeleteMapping("/deleteBatchFiles")
    @Operation(summary = "多文件删除")
    R<Void> deleteBatchFiles(
            @RequestParam("fileIds") @NotNull(message = "文件ID不能为空")
            @Parameter(name = "fileIds", required = true, description = "fileIds")
            List<Long> fileIds);
}